package com.xopencode.multithread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author Mcb
 * @date 2022/5/24
 * @apiNote 单线程开启callble
 */
public class TestCallble {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // new FutureTask<>(callable); futureTask实现runnable
        MyThread myThread = new MyThread();
        FutureTask<String> futureTask = new FutureTask<>(myThread);

        new Thread(futureTask, "RunThread").start();

        //get方法堵塞
        String result = futureTask.get();
        System.out.println("结果：" + result);
    }

    static class MyThread implements Callable<String> {
        @Override
        public String call() throws Exception {
            System.out.println("Call:" + Thread.currentThread().getName());
            return "String" + Thread.currentThread().getName();
        }
    }
}
